/*
    This file is part of FSJController.

    FSJController is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    FSJController is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FSJController.  If not, see <http://www.gnu.org/licenses/>.
*/

package de.qsc.fsjcontroller;

import java.util.UUID;

/**
 * Encapsulates a Freeswitch API commands, including server response
 * 
 * @author Andreas Mager <ama@qsc.de>
 */
public class FSAPICommand extends FSCommand {

    UUID uuid;
    private FSAPICommandCallback callback;
    
    /**
     * Creates a FSCommand object (API call)
     * 
     * @param command
     *            the Freeswitch API command, e.g. "originate"
     * @param args
     *            the command arguments
     * @param callback
     *            a callback object whose onSuccess() or onError() 
     *            methods are called when the command completes 
     */
    public FSAPICommand(String command, String args, FSAPICommandCallback callback) {
        uuid = null;
        this.command = command;
        this.args = args;
        this.callback = callback;
    }

    /**
     * Creates a FSCommand object (API call)
     * 
     * @param command
     *            the Freeswitch API command, e.g. "originate"
     * @param args
     *            the command arguments
     * @param callback
     *            a callback object whose onSuccess() or onError() 
     *            methods are called when the command completes 
     */
    public FSAPICommand(String command, String args) {
        this(command, args, null);
    }

    public void setUUID(UUID uuid) {
        this.uuid = uuid;
    }

    public UUID getUUID() {
        return uuid;
    }

    public void setCallback(FSAPICommandCallback callback) {
        this.callback = callback;
    }
    
    public FSAPICommandCallback getCallback() {
        return callback;
    }
    
    @Override
    byte[] getBytes() {
        return new String("bgapi " + command + " " + args + "\n\n").getBytes();
    }

    @Override
    public String toString() {
        return "bgapi " + command + " " + args;
    }
}
